package com.zlc.common.core.process.service.impl;

import com.zlc.common.common.service.BaseServiceImpl;
import com.zlc.common.core.process.model.entity.StoneProcessLog;
import com.zlc.common.core.process.mapper.StoneProcessLogMapper;
import com.zlc.common.core.process.model.vo.StoneProcessLogVo;
import com.zlc.common.core.process.service.StoneProcessLogService;
import com.zlc.common.core.user.model.vo.MayanPlatUserVo;
import com.zlc.common.core.user.service.MayanPlatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

/**
 * @author  zl
 * @date 2023-10-19 
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class StoneProcessLogServiceImpl extends BaseServiceImpl<StoneProcessLogMapper, StoneProcessLog, StoneProcessLogVo> implements StoneProcessLogService{

    @Autowired
    private StoneProcessLogService stoneProcessLogService;
    @Autowired
    private MayanPlatUserService mayanPlatUserService;

    @Override
    public void saveLog(String processInstanceId, String operateType, String operateUser, String content) {
        saveLog(processInstanceId,null,null,null,null,operateType,operateUser,content);
    }

    @Override
    public void saveLog(String processInstanceId, String processId, String nodeId,String nodeName, String taskId, String operateType, String operateUser, String content) {
        StoneProcessLogVo logVo = new StoneProcessLogVo();
        logVo.setLogContent(content);
        logVo.setProcessInstanceId(processInstanceId);
        logVo.setOperateType(operateType);
        logVo.setOperateUser(operateUser);
        if(!ObjectUtils.isEmpty(operateUser)){
            MayanPlatUserVo mayanPlatUserVo = mayanPlatUserService.queryByUserAccount(operateUser);
            if(!ObjectUtils.isEmpty(mayanPlatUserVo)){
                logVo.setOperateUserName(mayanPlatUserVo.getUsername());
            }
        }
        logVo.setProcessId(processId);
        logVo.setNodeId(nodeId);
        logVo.setNodeName(nodeName);
        logVo.setTaskId(taskId);
        stoneProcessLogService.saveVo(logVo);
    }
}
